#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File   : b_object_program_enum.py
# @Email  : xuexia_xu@feidee.com
# @Time   : 2024/3/29 10:33
# @Desc   : 面向对象高级编程：枚举

from enum import Enum, unique

# 获得了Month类型的枚举类，直接使用Month.Jan来引用一个常量，或者枚举它的所有成员
Month = Enum('Month', ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'))

# value属性则是自动赋给成员的int常量，默认从1开始计数
for name, member in Month.__members__.items():
    print(name, '=>', member, ',', member.value)


# @unique装饰器可以帮助我们检查保证没有重复值。
@unique
class Weekday(Enum):
    Sun = 0  # Sun的value被设定为0
    Mon = 1
    Tue = 2
    Wed = 3
    Thu = 4
    Fri = 5
    Sat = 6


if __name__ == "__main__":
    day1 = Weekday.Mon
    print(day1.value)
    print(Weekday(1))